<?php
use App\Models\Menu;
use App\Models\Permission;
use App\Models\Role;
use App\Models\User;
use Illuminate\Database\Seeder;

class RoleSeeder extends Seeder
{
    
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run() {
        $roleSeed = ['admin', 'managerLv1', 'managerLv2', 'staff', 'customerLv1', 'customerLv2', 'supplierLv1', 'supplierLv2'];
        
        array_map(function ($roleName) {
            DB::table('roles')->insert(['name' => $roleName ]);
        }, $roleSeed);
        // add admin permission to admin

        $adminRole = Role::findOrFail(1);
        $adminRole->permissions()->sync(Permission::all());
        // assign all menu permissions to admin
        $adminRole->menus()->sync(Menu::all());
        $user4Handle = User::findOrFail(3);
        $user4Handle->roles()->save($adminRole);

    }
}
